package org.groupg.utils;

import com.mifmif.common.regex.Generex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * 根据特定规则生成字符串内容的工具
 * 需要再本地安装python 以及 xeger 包 才能使用
 */
public class CreateStringUtils {
    static Logger log = LoggerFactory.getLogger(CreateStringUtils.class);

    /**
     * @param format 格式化数据
     *               %04d 输出：0001
     */
    public synchronized static String createStrByNumberFormat(String format, Integer now) {
        return String.format(format, now);
    }

    public synchronized static String createStrByRegExRandom(String regex) throws IOException, InterruptedException {
        Generex generex = new Generex(regex);
        // Generate random String
        return generex.random();
    }

    public static void main(String[] args) throws IOException, InterruptedException {
//        System.out.println(createStrByNumberFormat("String：%04d",1));
        log.debug(createStrByRegExRandom("[\\u4e00-\\u9fa5]{6,8}[a-z|A-Z]{6,8}[1-9]([0-9]{4,10})"));
    }
}
